'use strict';

/**
 * @ngdoc function
 * @name appApp.controller:HomeCtrl
 * @description
 * # HomeCtrl
 * Controller of the appApp
 */
angular.module('appApp')
  .controller('HomeCtrl', function ($scope, $timeout, $location, $rootScope, yzFactory, uploadImg) {
    $timeout(function() {
        var swiper = new Swiper ('.swiper-container', {
          direction: 'horizontal',
          loop: true,
          pagination : '.swiper-pagination',
          paginationClickable :true,
        })
    },10);

    $scope.foot_tag = 0;
    $scope.change_foot = function(flag){
      $scope.foot_tag = flag;
      if(flag == 0){
        $location.url('home');
      }
      if(flag == 1){
        $location.url('jzservice');
      }
      if(flag == 2){
        window.open('http://www.zjsyzw.com/index.php/welcome/index');
        $scope.foot_tag = 0;
      }
    }
    // 跳转到中心介绍
    $scope.gotoCenterIntro = function(){
      $location.url('introduction/0');
    }
    // 跳转到就诊预约
    $scope.gotoAppointment = function(){
      window.open('https://wx.wy.guahao.com/fastorder/expertlist?hospitalId=8f113a19-eee7-47b8-9517-2ad069a2f57a000&deptId=4ef460fb-906f-4d6c-93fd-7fc68209ee66000&_channel=/');
    }
    // 跳转到联系我们
    $scope.gotoContactUs = function(){
      $location.url('introduction/2');
    }
    // 跳转到了解尿毒症
    $scope.gotoKonwNdz = function(){
      $location.url('know-ndz');
    }
    // 跳转到了解肾移植
    $scope.gotoKonwKidneytp = function(){
      $location.url('know-kidneytp');
    }
    // 跳转到肾移植过程
    $scope.gotoKitneytpProcess = function(){
      $location.url('kidneytp-process');
    }
    // 获取新闻列表
    $scope.getNewslist = function(){
      yzFactory.index.news(function(data){
            $scope.news = data.info;
          },function(data){
            alert(data.data.info);
        });
    }
    $scope.getNewslist();
    // 跳转到新闻详情
    $scope.gotoNewsDetail = function(id){
      $location.url('news-centerdetail/' + id);
    }
    // 跳转到新闻中心
    $scope.gotoNewsCenter = function(){
      $location.url('news-center');
    }
    // 跳转到在线问答
    $scope.gotoOnline = function(){
      window.open('http://www.zjsyzw.com/index.php/welcome/index');
    }
    // 跳转到儿童公益
    $scope.gotoGongyi = function(){
      window.open('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc0db45f411664b2e&redirect_uri=https%3A%2F%2Fssl.gongyi.qq.com%2Fm%2Fweixin%2Fdetail.htm%3Fshowwxpaytitle%3D1%26et%3Dfx%26from%3Dmessage%26isappinstalled%3D1%23p%253Ddetail%2526id%253D15694&response_type=code&scope=snsapi_base#wechat_redirect');
    }

    wx.ready(function(){
      wx.onMenuShareTimeline({
        title: '首页 | 曾教授移植网微信平台', // 分享标题
        link: 'http://wechat.zjsyzw.com/home/index/home', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: 'http://wechat.zjsyzw.com/Public/app/dist/images/logo.png', // 分享图标
        success: function () { 
            // 用户确认分享后执行的回调函数
        },
        cancel: function () { 
            // 用户取消分享后执行的回调函数
        }
      });
      // 获取“分享给朋友”按钮点击状态及自定义分享内容接口
      wx.onMenuShareAppMessage({
        title: '首页',  // 分享标题
        desc: '曾教授移植网微信平台', // 分享描述
        link: 'http://wechat.zjsyzw.com/home/index/home', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
        imgUrl: 'http://wechat.zjsyzw.com/Public/app/dist/images/logo.png', // 分享图标
        type: '', // 分享类型,music、video或link，不填默认为link
        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
        success: function () { 
            // 用户确认分享后执行的回调函数
        },
        cancel: function () { 
            // 用户取消分享后执行的回调函数
        }
      });
    });
    
  });
